//
//  Tools.swift
//  XCBlue
//
//  Created by mac on 2025/2/13.
//

import Foundation

//将data转为string
func convertToNSString(data: Data) -> String? {
    let bytes = [UInt8](data)
    var result = ""
    
    for byte in bytes {
        result.append(String(format: "%02lx", byte))
    }
    
    return result
}

// 根据 formatter 格式获取目前的时间字符串
func getDateWithFormatterString(formatter: String) -> String {
    let dateFormatter = DateFormatter()
    dateFormatter.dateFormat = formatter.isEmpty ? "yyyyMMddHHmmss" : formatter
    dateFormatter.locale = Locale(identifier: "en_US_POSIX")
    dateFormatter.calendar = Calendar(identifier: .gregorian)
    return dateFormatter.string(from: Date())
}
